package ua.amsoft.brelok.manager;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import org.apache.http.client.ClientProtocolException;

import ua.amsoft.brelok.task.AuthenticationTask;
import android.util.Log;

public class AuthenticationManager {
    
    private static final String TAG = AuthenticationManager.class.getName();
    
    /**
     * Checks device authentication
     * 
     * @param url
     * @param imei
     * @return <code>boolean true</code> or <code>false</code> is device
     *         authenticated
     * @throws ClientProtocolException
     * @throws IOException
     */
    public boolean checkAuthentication(final String url, final String imei)
            throws ClientProtocolException, IOException {
        final AuthenticationTask authenticationTask = new AuthenticationTask();
        boolean authenticated = false;
        try {
            authenticated = authenticationTask.execute(url, imei).get();
        } catch (final InterruptedException e) {
            Log.e(AuthenticationManager.TAG, e.getLocalizedMessage());
        } catch (final ExecutionException e) {
            Log.e(AuthenticationManager.TAG, e.getLocalizedMessage());
        }
        return authenticated;
    }
    
}
